<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        main{
            margin-top: 50px;
        }
        .col-1{
            height: 500px;
            padding-right: 100px;
            border-right: 1px solid #999;
        }
        .col-2{
            margin-left: 100px;
        }
        .input1{
            width: 300px;
            margin-right: 20px;
            height: 40px;
            border: 1px solid #5131b6;
            outline: none;
            padding: 10px;
            font-size: 16px;
            border-radius: 5px;
        }
        .input2{
            padding: 5px 10px;
            font-size: 14px;
            color: #000;
            outline: none;
            border: 1px solid #5131b6;
            border-radius: 5px;
            background: white;
            cursor: pointer;
            margin-right: 10px;
        }
        .input2:hover{
            color: white;
            background: #5131b6;
            transition: 1s;
        }
        .col-2{
            width: 430px;;
        }
        .col-2 ul li{
            padding: 5px 10px;
            margin: 5px 0;
            font-size: 18px;
            cursor: pointer;
            white-space:unset
        }
        .col-2 ul li:hover{
            background-color: #dedede;
            border-radius: 5px;
            transition: .5s;

        }
    </style>
</head>
<body>
<header>
    <div class="container">
        <div class="flex">
            <div class="he">
                <img src="img/gse.png" alt="">
            </div>
            <div class="ha">
                <input type="text" placeholder="搜索">
                <h2>待办事项</h2>
            </div>
        </div>
    </div>
</header>
<main>
    <div class="container clearfix">
        <div class="col-1" style="float: left">
            <input type="text" id="text"  class="input1"/>
            <input id="add" type="button" value="添加" class="input2"/>
            <div style="margin-top: 20px;">
                <input type="button" value="选择全部" id="selectAll"  class="input2"/>
                <input type="button" value="删除" id="remove"  class="input2"/>
                <input type="button" value="删除全部" id="removeAll" class="input2" />
            </div>
        </div>
        <div class="col-2" style="float: left">

            <ul id="list">
            </ul>

        </div>

    </div>
</main>
<script>
    window.onload = function () {
        function getById (id) {
            return document.getElementById(id);
        }

        var input = getById('text');
        var add = getById('add');
        var selectAll = getById('selectAll');
        var removeAll = getById('removeAll');
        var remove = getById('remove');
        var list = getById('list');

        add.onclick = function () {
            var inputValue = input.value;
            var li;
            if (inputValue) {
                li = document.createElement('li');
                li.innerHTML = '<input type="checkbox" />' + input.value;
                input.value = '';
                list.appendChild(li);
            }
        };

        selectAll.onclick = function () {
            var cks = list.getElementsByTagName('input');
            var i;
            var length = cks.length;
            var ck;
            for (i = 0; i < length; i++) {
                ck = cks[i];
                if(!ck.checked) {
                    ck.checked = true;
                }
            }
        };

        remove.onclick = function () {
            var cks = list.getElementsByTagName('input');
            var i;
            var ck;
            var li;
            for (i = cks.length - 1; i >= 0; i--) {
                ck = cks[i];
                if(ck.checked) {
                    li = ck.parentNode;
                    li.parentNode.removeChild(li);
                }
            }
        };

        removeAll.onclick = function () {
            list.innerHTML = '';
        };
    }
</script>

</body>
</html>